﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Blogs.Model;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Modules.News;

namespace Migration.Classes
{
	public static class MigrationComments
	{
		public static void AddCommentsToGenericContent(Guid id, List<Telerik.Sitefinity.Services.Migration.MigrationComment> comments, string language)
		{
			var fluent = App.WorkWith();

			foreach (Telerik.Sitefinity.Services.Migration.MigrationComment comment in comments)
			{
				fluent
					.ContentItem(id)
					.GetLive()
					.Comment()
					.CreateNew()
					.Do(c =>
					{
						if (MigrationCultures.IsMultilingual)
						{
							c.Content[language] = comment.Text;
							c.AuthorName[language] = comment.Author;
						}
						else
						{
							c.Content = comment.Text;
							c.AuthorName = comment.Author;
						}
						c.DateCreated = DateTime.UtcNow;
						c.IpAddress = comment.IpAddress;
						c.Email = comment.Email;
						c.Website = comment.WebSite;
						c.Visible = comment.Visible;
					})
					.Done();
			}

			fluent.Dispose();
		}

		public static void AddCommentsToNewsItem(Guid id, List<Telerik.Sitefinity.Services.Migration.MigrationComment> comments, string language)
		{
			var fluent = App.WorkWith();

			foreach (Telerik.Sitefinity.Services.Migration.MigrationComment comment in comments)
			{
				fluent
					.NewsItem(id)
					.GetLive()
					.Comment()
					.CreateNew()
					.Do(c =>
					{
						if (MigrationCultures.IsMultilingual)
						{
							c.Content[language] = comment.Text;
							c.AuthorName[language] = comment.Author;
						}
						else
						{
							c.Content = comment.Text;
							c.AuthorName = comment.Author;
						}
						c.DateCreated = DateTime.UtcNow;
						c.IpAddress = comment.IpAddress;
						c.Email = comment.Email;
						c.Website = comment.WebSite;
						c.Visible = comment.Visible;
					})
					.Done();
			}

			fluent.Dispose();
		}

		public static void AddCommentsToBlogPost(Guid id, List<Telerik.Sitefinity.Services.Migration.MigrationComment> comments, string language)
		{
			var fluent = App.WorkWith();

			foreach (Telerik.Sitefinity.Services.Migration.MigrationComment comment in comments)
			{
				fluent
					.BlogPost(id)
					.GetLive()
					.Comment()
					.CreateNew()
					.Do(c =>
					{
						if (MigrationCultures.IsMultilingual)
						{
							c.Content[language] = comment.Text;
							c.AuthorName[language] = comment.Author;
						}
						else
						{
							c.Content = comment.Text;
							c.AuthorName = comment.Author;
						}
						
						c.DateCreated = DateTime.UtcNow;
						c.IpAddress = comment.IpAddress;
						c.Email = comment.Email;
						c.Website = comment.WebSite;
						c.Visible = comment.Visible;
					})
					.Done();
			}

			fluent.Dispose();
		}

		public static void AddCommentsToEvent(Guid id, List<Telerik.Sitefinity.Services.Migration.MigrationComment> comments, string language)
		{
			var fluent = App.WorkWith();

			foreach (Telerik.Sitefinity.Services.Migration.MigrationComment comment in comments)
			{
				fluent
					.Event(id)
					.GetLive()
					.Comment()
					.CreateNew()
					.Do(c =>
					{
						if (MigrationCultures.IsMultilingual)
						{
							c.Content[language] = comment.Text;
							c.AuthorName[language] = comment.Author;
						}
						else
						{
							c.Content = comment.Text;
							c.AuthorName = comment.Author;
						}
						c.DateCreated = DateTime.UtcNow;
						c.IpAddress = comment.IpAddress;
						c.Email = comment.Email;
						c.Website = comment.WebSite;
						c.Visible = comment.Visible;
					})
					.Done();
			}

			fluent.Dispose();
		}

		/*
		public static void AddCommentsToLibraryItem(Guid id, List<Telerik.Sitefinity.Services.Migration.MigrationComment> comments)
		{
			var fluent = App.WorkWith();

			foreach (Telerik.Sitefinity.Services.Migration.MigrationComment comment in comments)
			{
				fluent
					.Album(id)
					.GetLive()
					.Comment()
					.CreateNew()
					.Do(c =>
					{
						c.Content = comment.Text;
						c.DateCreated = DateTime.UtcNow;
						c.AuthorName = comment.Author;
						c.IpAddress = comment.IpAddress;
						c.Email = comment.Email;
						c.Website = comment.WebSite;
						c.Visible = comment.Visible;
					})
					.Done();
			}

			fluent.Dispose();
		}
		*/
	}
}
